package com.ruoyi.web.controller.room;

import com.cdtu.room.domain.Equipment;
import com.cdtu.room.dto.EquipmentDto;
import com.cdtu.room.service.IEquipmentService;
import com.cdtu.room.vo.EquipmentVo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会议室设备Controller
 * 
 * @author hcc
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/room/equipment")
public class EquipmentController extends BaseController
{
    @Autowired
    private IEquipmentService equipmentService;

    /**
     * 查询会议室设备列表
     */
    @PreAuthorize("@ss.hasPermi('room:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Equipment equipment)
    {
        startPage();
        List<Equipment> list = equipmentService.selectEquipmentList(equipment);
        return getDataTable(list);
    }
    /**
     * 查询会议室设备列表
     */
    @PreAuthorize("@ss.hasPermi('room:equipment:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(EquipmentVo equipmentVo)
    {
        startPage();
        List<EquipmentDto> list = equipmentService.getEquipmentList(equipmentVo);
        return getDataTable(list);
    }

    /**
     * 导出会议室设备列表
     */
    @PreAuthorize("@ss.hasPermi('room:equipment:export')")
    @Log(title = "会议室设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Equipment equipment)
    {
        List<Equipment> list = equipmentService.selectEquipmentList(equipment);
        ExcelUtil<Equipment> util = new ExcelUtil<Equipment>(Equipment.class);
        util.exportExcel(response, list, "会议室设备数据");
    }

    /**
     * 获取会议室设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('room:equipment:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") Long equipmentId)
    {
        return success(equipmentService.selectEquipmentByEquipmentId(equipmentId));
    }

    /**
     * 新增会议室设备
     */
    @PreAuthorize("@ss.hasPermi('room:equipment:add')")
    @Log(title = "会议室设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Equipment equipment)
    {
        return toAjax(equipmentService.insertEquipment(equipment));
    }

    /**
     * 修改会议室设备
     */
    @PreAuthorize("@ss.hasPermi('room:equipment:edit')")
    @Log(title = "会议室设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Equipment equipment)
    {
        return toAjax(equipmentService.updateEquipment(equipment));
    }

    /**
     * 删除会议室设备
     */
    @PreAuthorize("@ss.hasPermi('room:equipment:remove')")
    @Log(title = "会议室设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentId}")
    public AjaxResult remove(@PathVariable Long equipmentId)
    {
        return toAjax(equipmentService.deleteEquipmentByEquipmentId(equipmentId));
    }
}
